package com.jjw.springbootcvs.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jjw.springbootcvs.mapper.SupplierMapper;
import com.jjw.springbootcvs.pojo.dto.SupplierDTO;
import com.jjw.springbootcvs.pojo.entity.Supplier;
import com.jjw.springbootcvs.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xiaojuan
 * @Date 2024/11/2
 * @Description
 */
@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierMapper supplierMapper;

    @Override
    public List<Supplier> getSupplierList() {
        return supplierMapper.getSupplierList();
    }

    @Override
    public PageInfo<Supplier> getAllSupplierListPage(SupplierDTO supplierDTO) {
        PageHelper.startPage(supplierDTO.getPageIndex() == null ? 1 : supplierDTO.getPageIndex(),10);
        List<Supplier> supplierList = supplierMapper.getAllSupplierListPage(supplierDTO);
        return new PageInfo<>(supplierList);
    }

    @Override
    public void add(Supplier supplier) {
        supplierMapper.insertSelective(supplier);
    }

    @Override
    public Supplier getSupplierById(Long id) {
        return supplierMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(Supplier supplier) {
        supplierMapper.updateByPrimaryKeySelective(supplier);
    }

    @Override
    public void delete(Long id) {
        supplierMapper.deleteByPrimaryKey(id);
    }
}
